import Vue from 'vue';
import Vuex from 'vuex';
import { Request } from '../request';

export interface BlogItem {
    author: string;
    content: string;
    id: number;
    createTime: number;
}

export interface State {
    skin: {},
    user: {
        name: string;
    };
    userinfo: {};
    banner: [],
    home: {
        news: [],
    };
    blogList: BlogItem[];
}

Vue.use(Vuex);

/**
 * 提供一个工厂函数创建 store
 */

export const store = new Vuex.Store<State>({
    state: {
        skin: {},
        user: {
            name: ''
        },
        banner: [],
        home: {
            news: [],
        },
        userinfo: {},
        blogList: []
    },
    mutations: {
        setSkin(state, data) {
            state.skin = data;
        },
        getBanner(state, data: []) {
            state.banner = data;
        },
        getHomeNewsList(state, data: []) {
            state.home.news = data;
        },
        // 
        signin(state, name: string) {
            state.user.name = name;
        },
        getBlogList(state, data: BlogItem[]) {
            state.blogList = data;
        },
    },
    actions: {
        SETSKIN: ({ commit }, data) => {
            // console.log(data);

            // commit('setSkin', data)
        }
    }
});
export const createStore = (request: Request) => {
    return store;
};
